
import GlobalEvent from "../../../cfw/event/GlobalEvent";
import { EventName } from "../../../public/Config";
import CookeryRoomStep from "./CookeryRoomStep";
import CookeryController from "../CookeryController";
import CookeryManager from "../CookeryManager";
import TextureRenderUtils from "../../../engine/TextureRenderUtils";
import SDKManager from "../../../sdk/SDKManager";
const { ccclass, property } = cc._decorator;

@ccclass
export default class CookeryRoomStep8 extends CookeryRoomStep {

    @property([cc.Sprite])
    star: cc.Sprite[] = [];

    // @property(CaptureComp)
    // capture: CaptureComp = null;

    protected controller: CookeryController;

    protected model: CookeryManager;

    onButtonNextClick() {
        this.finish()
    }
    finish() {
        cc.log(' finish == ')
        GlobalEvent.instance().emit(EventName.UPDATE_COOKIE_STEP, 8)
    }


    start() {
        this.controller = CookeryController.instance();
        this.model = CookeryManager.instance();
        this.node.active = true;
        let hasSystem: boolean = SDKManager.getChannel().cantUseImageDataURL()
        for (let index = 0; index < this.star.length; index++) {
            const element = this.star[index];
            if (hasSystem) {
                element.node.scaleY = -1;
                element.spriteFrame = TextureRenderUtils.getSpriteFrameByTextureInfo(this.controller.getTextureInfo())
            } else {
                // element.spriteFrame = TextureRenderUtils.getSpriteFrameByDataUrl(this.controller.getDataUrl());
                TextureRenderUtils.getSpriteFrameByDataUrl(this.controller.getDataUrl(), (sf: cc.SpriteFrame) => {
                    if (cc.isValid(this.node))
                        element.spriteFrame = sf
                });
            }

        }

    }

    onDestroy() {

    }

}
